home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Ghostscript / source / gscolor1.c < prev    next >
C/C++ Source or Header  |  1997-04-24  |  7KB  |  227 lines

  1. /* Copyright (C) 1989, 1992, 1993, 1994, 1996, 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gscolor.c */
  20. /* Level 1 extended color operators for Ghostscript library */
  21. #include "gx.h"
  22. #include "gserrors.h"
  23. #include "gsstruct.h"
  24. #include "gsutil.h"            /* for gs_next_ids */
  25. #include "gsccolor.h"
  26. #include "gxcspace.h"
  27. #include "gxdcconv.h"
  28. #include "gxdevice.h"            /* for gx_color_index */
  29. #include "gxcmap.h"
  30. #include "gzstate.h"
  31. #include "gscolor1.h"
  32.  
  33. /* Imports from gscolor.c */
  34. void load_transfer_map(P3(gs_state *, gx_transfer_map *, floatp));
  35.  
  36. /* Imported from gsht.c */
  37. void gx_set_effective_transfer(P1(gs_state *));
  38.  
  39. /* Define the CMYK color space type. */
  40. extern cs_proc_remap_color(gx_remap_DeviceCMYK);
  41. extern cs_proc_concretize_color(gx_concretize_DeviceCMYK);
  42. extern cs_proc_remap_concrete_color(gx_remap_concrete_DCMYK);
  43. const gs_color_space_type
  44.     gs_color_space_type_DeviceCMYK =
  45.      { gs_color_space_index_DeviceCMYK, 4, true,
  46.        gx_init_paint_4, gx_same_concrete_space,
  47.        gx_concretize_DeviceCMYK, gx_remap_concrete_DCMYK,
  48.        gx_remap_DeviceCMYK, gx_no_install_cspace,
  49.        gx_no_adjust_cspace_count, gx_no_adjust_color_count,
  50.        gx_no_cspace_enum_ptrs, gx_no_cspace_reloc_ptrs
  51.      };
  52.  
  53. /* Initialize the permanent color space instance (declared in gscolor.c). */
  54. extern const gs_color_space *gs_cs_static_DeviceCMYK;
  55. void
  56. gs_gscolor1_init(gs_memory_t *mem)
  57. {    gs_color_space *pcs =
  58.       gs_alloc_struct(mem, gs_color_space, &st_color_space,
  59.               "gs_cs_static_DeviceCMYK");
  60.     pcs->type = &gs_color_space_type_DeviceCMYK;
  61.     gs_cs_static_DeviceCMYK = pcs;
  62. }
  63.  
  64. /* setcmykcolor */
  65. int
  66. gs_setcmykcolor(gs_state *pgs, floatp c, floatp m, floatp y, floatp k)
  67. {    gs_client_color *pcc = pgs->ccolor;
  68.     if ( pgs->in_cachedevice ) return_error(gs_error_undefined);
  69.     cs_adjust_counts(pgs, -1);
  70.     pcc->paint.values[0] = c;
  71.     pcc->paint.values[1] = m;
  72.     pcc->paint.values[2] = y;
  73.     pcc->paint.values[3] = k;
  74.     pcc->pattern = 0;            /* for GC */
  75.     pgs->color_space->type = &gs_color_space_type_DeviceCMYK;
  76.     gx_unset_dev_color(pgs);
  77.     return 0;
  78. }
  79.  
  80. /* currentcmykcolor */
  81. int
  82. gs_currentcmykcolor(const gs_state *pgs, float pr4[4])
  83. {    const gs_client_color *pcc = pgs->ccolor;
  84.     switch ( pgs->color_space->type->index )
  85.     {
  86.     case gs_color_space_index_DeviceGray:
  87.         pr4[0] = pr4[1] = pr4[2] = 0.0;
  88.         pr4[3] = 1.0 - pcc->paint.values[0];
  89.         break;
  90.     case gs_color_space_index_DeviceRGB:
  91.     {    frac fcmyk[4];
  92.         color_rgb_to_cmyk(
  93.             float2frac(pcc->paint.values[0]),
  94.             float2frac(pcc->paint.values[1]),
  95.             float2frac(pcc->paint.values[2]),
  96.             (const gs_imager_state *)pgs, fcmyk);
  97.         pr4[0] = frac2float(fcmyk[0]);
  98.         pr4[1] = frac2float(fcmyk[1]);
  99.         pr4[2] = frac2float(fcmyk[2]);
  100.         pr4[3] = frac2float(fcmyk[3]);
  101.     }    break;
  102.     case gs_color_space_index_DeviceCMYK:
  103.         pr4[0] = pcc->paint.values[0];
  104.         pr4[1] = pcc->paint.values[1];
  105.         pr4[2] = pcc->paint.values[2];
  106.         pr4[3] = pcc->paint.values[3];
  107.         break;
  108.     default:
  109.         pr4[0] = pr4[1] = pr4[2] = 0.0;
  110.         pr4[3] = 1.0;
  111.     }
  112.     return 0;
  113. }
  114.  
  115. /* setblackgeneration */
  116. /* Remap=0 is used by the interpreter. */
  117. int
  118. gs_setblackgeneration(gs_state *pgs, gs_mapping_proc proc)
  119. {    return gs_setblackgeneration_remap(pgs, proc, true);
  120. }
  121. int
  122. gs_setblackgeneration_remap(gs_state *pgs, gs_mapping_proc proc, bool remap)
  123. {    rc_unshare_struct(pgs->black_generation, gx_transfer_map,
  124.               &st_transfer_map, pgs->memory,
  125.               return_error(gs_error_VMerror),
  126.               "gs_setblackgeneration");
  127.     pgs->black_generation->proc = proc;
  128.     pgs->black_generation->id = gs_next_ids(1);
  129.     if ( remap )
  130.     {    load_transfer_map(pgs, pgs->black_generation, 0.0);
  131.         gx_unset_dev_color(pgs);
  132.     }
  133.     return 0;
  134. }
  135.  
  136. /* currentblackgeneration */
  137. gs_mapping_proc
  138. gs_currentblackgeneration(const gs_state *pgs)
  139. {    return pgs->black_generation->proc;
  140. }
  141.  
  142. /* setundercolorremoval */
  143. /* Remap=0 is used by the interpreter. */
  144. int
  145. gs_setundercolorremoval(gs_state *pgs, gs_mapping_proc proc)
  146. {    return gs_setundercolorremoval_remap(pgs, proc, true);
  147. }
  148. int
  149. gs_setundercolorremoval_remap(gs_state *pgs, gs_mapping_proc proc, bool remap)
  150. {    rc_unshare_struct(pgs->undercolor_removal, gx_transfer_map,
  151.               &st_transfer_map, pgs->memory,
  152.               return_error(gs_error_VMerror),
  153.               "gs_setundercolorremoval");
  154.     pgs->undercolor_removal->proc = proc;
  155.     pgs->undercolor_removal->id = gs_next_ids(1);
  156.     if ( remap )
  157.     {    load_transfer_map(pgs, pgs->undercolor_removal, -1.0);
  158.         gx_unset_dev_color(pgs);
  159.     }
  160.     return 0;
  161. }
  162.  
  163. /* currentundercolorremoval */
  164. gs_mapping_proc
  165. gs_currentundercolorremoval(const gs_state *pgs)
  166. {    return pgs->undercolor_removal->proc;
  167. }
  168.  
  169. /* setcolortransfer */
  170. /* Remap=0 is used by the interpreter. */
  171. int
  172. gs_setcolortransfer_remap(gs_state *pgs, gs_mapping_proc red_proc,
  173.   gs_mapping_proc green_proc, gs_mapping_proc blue_proc,
  174.   gs_mapping_proc gray_proc, bool remap)
  175. {    gx_transfer_colored *ptran = &pgs->set_transfer.colored;
  176.     gx_transfer_colored old;
  177.     gs_id new_ids = gs_next_ids(4);
  178.  
  179.     old = *ptran;
  180.     rc_unshare_struct(ptran->gray, gx_transfer_map, &st_transfer_map,
  181.               pgs->memory, goto fgray, "gs_setcolortransfer");
  182.     rc_unshare_struct(ptran->red, gx_transfer_map, &st_transfer_map,
  183.               pgs->memory, goto fred, "gs_setcolortransfer");
  184.     rc_unshare_struct(ptran->green, gx_transfer_map, &st_transfer_map,
  185.               pgs->memory, goto fgreen, "gs_setcolortransfer");
  186.     rc_unshare_struct(ptran->blue, gx_transfer_map, &st_transfer_map,
  187.               pgs->memory, goto fblue, "gs_setcolortransfer");
  188.     ptran->gray->proc = gray_proc;
  189.     ptran->gray->id = new_ids;
  190.     ptran->red->proc = red_proc;
  191.     ptran->red->id = new_ids + 1;
  192.     ptran->green->proc = green_proc;
  193.     ptran->green->id = new_ids + 2;
  194.     ptran->blue->proc = blue_proc;
  195.     ptran->blue->id = new_ids + 3;
  196.     if ( remap )
  197.     {    load_transfer_map(pgs, ptran->red, 0.0);
  198.         load_transfer_map(pgs, ptran->green, 0.0);
  199.         load_transfer_map(pgs, ptran->blue, 0.0);
  200.         load_transfer_map(pgs, ptran->gray, 0.0);
  201.         gx_set_effective_transfer(pgs);
  202.         gx_unset_dev_color(pgs);
  203.     }
  204.     return 0;
  205. fblue:    rc_assign(ptran->green, old.green, "setcolortransfer");
  206. fgreen:    rc_assign(ptran->red, old.red, "setcolortransfer");
  207. fred:    rc_assign(ptran->gray, old.gray, "setcolortransfer");
  208. fgray:    return_error(gs_error_VMerror);
  209. }
  210. int
  211. gs_setcolortransfer(gs_state *pgs, gs_mapping_proc red_proc,
  212.   gs_mapping_proc green_proc, gs_mapping_proc blue_proc,
  213.   gs_mapping_proc gray_proc)
  214. {    return gs_setcolortransfer_remap(pgs, red_proc, green_proc,
  215.                      blue_proc, gray_proc, true);
  216. }
  217.  
  218. /* currentcolortransfer */
  219. void
  220. gs_currentcolortransfer(const gs_state *pgs, gs_mapping_proc procs[4])
  221. {    const gx_transfer_colored *ptran = &pgs->set_transfer.colored;
  222.     procs[0] = ptran->red->proc;
  223.     procs[1] = ptran->green->proc;
  224.     procs[2] = ptran->blue->proc;
  225.     procs[3] = ptran->gray->proc;
  226. }
  227.